<?php
namespace app\admins\controller;
use think\Controller;
use Util\data\Sysdb;



class Slide extends BaseAdmin
{
	public function index(){
		$data['lists']=$this->db->table('slide')->lists();
		$this->assign('data',$data);
		return $this->fetch();
	}

	//添加编辑幻灯片
	public function add(){
		$id=(int)input('get.id');
		$data=$this->db->table('slide')->where(array('id'=>$id))->item();

		$this->assign('data',$data);
		return $this->fetch();
	}

	//保存幻灯片
	public function save(){
		$id=(int)input('post.id');
		$data['type']=trim(input('post.type'));
		$data['title']=trim(input('post.title'));
		$data['ord']=trim(input('post.ord'));
		$data['url']=trim(input('post.url'));
		$data['img']=trim(input('post.img'));

		if($id>0){
			$res=$this->db->table('slide')->where(array('id'=>$id))->update($data);
		}else{
			$res=$this->db->table('slide')->insert($data);
		}
		if(!$res){
			exit(json_encode(array('code'=>1,'msg'=>'保存失败')));

		}else{
			exit(json_encode(array('code'=>0,'msg'=>'保存成功')));

		}	
		
	}

	//删除幻灯片
	public function delete(){
		$id=(int)input('post.id');
		$this->db->table('slide')->where(array('id'=>$id))->delete();
		exit(json_encode(array('code'=>0,'msg'=>'删除成功')));
	}



}